<template>
	<view class="userpassword">
		<input type="text" v-model="password_1" placeholder-style="font-size:14px" placeholder="请输入原密码" />
		<input type="password" v-model="password_2" placeholder-style="font-size:14px" placeholder="请输入新密码" />
		<input type="password" v-model="password_3" placeholder-style="font-size:14px" placeholder="再次输入新密码" />
		<button class="btn" @click="changePwd" :loading="loading" :disabled="loading">
			立即修改
		</button>
	</view>
</template>

<script>
	import {
		changePwd
	} from "@/api/api.js"
	export default {
		data() {
			return {
				password_1: '',
				password_2: '',
				password_3: '',
				loading: false
			}
		},
		onLoad() {

		},
		methods: {
			changePwd() {
				if (this.password_1 == '') {
					return uni.$showMsg('请输入原密码')
				}
				if (this.password_2 == '') {
					return uni.$showMsg('请输入新密码')
				}
				if (this.password_2 != this.password_3) {
					return uni.$showMsg('两次密码不一致')
				}

				changePwd({
					old_password: this.password_1,
					new_password: this.password_2,
					new_password_re: this.password_3
				}).then(res => {
					uni.$showMsg(res.message)
					if (res.status == 1) {
						setTimeout(() => {
							uni.removeStorageSync('token')
							uni.reLaunch({
								url: '/pages/login/index'
							})
						}, 500)
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.userpassword {
		padding-top: 20rpx;

		input {
			background: #FFFFFF;
			width: 80%;
			padding: 5%;
			margin: 10px auto;
			border-radius: 16rpx;
		}
	}
</style>